<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<meta charset="utf-8">
<head></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-taxDeclaration-edit">
        <input id="declarationId" name="declarationId" value="${taxDeclaration.declarationId}" type="hidden">
        <input id="taskId" name="taskId" value="${taskId}" type="hidden">

        <div class="form-group">
            <label class="col-sm-3 control-label">税种：</label>
            <div class="col-sm-8">
                <select id="declarationTaxType" name="declarationTaxType" class="form-control">

                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">税目：</label>
            <div class="col-sm-8">
                <select id="declarationTaxModel" name="declarationTaxModel" class="form-control">

                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">计税依据：</label>
            <div class="col-sm-8">
                <input id="declarationTaxBasis" name="declarationTaxBasis" value="${taxDeclaration.declarationTaxBasis}"
                       class="form-control" type="text"
                       readonly="readonly">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">应纳税项目：</label>
            <div class="col-sm-8">
                <input id="declarationTaxProject" name="declarationTaxProject"
                       value="${taxDeclaration.declarationTaxProject}" class="form-control" type="text">
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">扣除项目及标准：</label>
            <div class="col-sm-8">
                <select id="declarationTaxCondition" name="declarationTaxCondition" class="form-control"
                        onchange="doChange()">

                </select>


            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">适用税率(%)：</label>
            <div class="col-sm-8">
                <input id="declarationTaxRate" name="declarationTaxRate" value="${taxDeclaration.declarationTaxRate}"
                       class="form-control" type="text"
                       readonly="readonly">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">应纳税额：</label>
            <div class="col-sm-8">
                <input id="declarationTaxMoney" name="declarationTaxMoney" value="${taxDeclaration.declarationTaxMoney}"
                       class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">代收代缴税额：</label>
            <div class="col-sm-8">
                <input id="declarationReplaceMoney" name="declarationReplaceMoney"
                       value="${taxDeclaration.declarationReplaceMoney}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">税款所属期限：</label>
            <div class="col-sm-8">
                <input id="declarationTaxTime" name="declarationTaxTime" class="form-control" type="text"
                       readonly="readonly">
            </div>
        </div>

        <c:if test="${ not empty taskId}">
            <div class="form-group">
                <label class="col-sm-3 control-label">&nbsp;</label>
                <div class="col-sm-8">
                    <a class="btn btn-primary btn-del" onclick="submitHandler()">
                        <i class="fa fa-play"></i>
                        提交审核
                    </a>
                </div>
            </div>
        </c:if>
    </form>
</div>
<script src="${ctx}/static/js/tax.json"></script>
<script type="text/javascript">
    var prefix = "${ctx}/system/declaration";

    $("#form-taxDeclaration-edit").validate({
        rules: {
            declarationTaxType: {
                required: true,
            },
            declarationTaxProject: {
                required: false,
            },
            declarationTaxModel: {
                required: true,
            },
            declarationTaxTime: {
                required: true,
            },
            declarationReplaceMoney: {
                required: true,
                range: [1, 100000000000]
            },
            declarationTaxMoney: {
                required: true,
                range: [1, 100000000000]
            }, declarationTaxCondition: {
                required: true
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-taxDeclaration-edit').serialize());
            window.parent.go();
        }
    }


    //获得省级下拉框对象
    var province = $("#declarationTaxType");
    var option = "<option value=''>--请选择--</option>";
    //遍历省市数据,并把里面省的数据追加到option选项中
    for (var i = 0; i < china.length; i++) {
        option += "<option value='" + china[i].p_id + "'  ";
        if ('${taxDeclaration.declarationTaxType}' == china[i].p_id) {
            option += " selected ";
        }
        option += ">" + china[i].p_name + "</option>";
    }
    province.append(option);

    if ('${taxDeclaration.declarationTaxType}' != "") {
        changeCar('${taxDeclaration.declarationTaxType}');
        changeCondition('${taxDeclaration.declarationTaxType}');
    }


    //省级下拉框发生改变事件
    $("#declarationTaxType").change(function () {
        //获取当前点击对象的值
        var proid = $(this).val();
        changeCar(proid);
        changeCondition(proid);
        var str = "";
        if (proid == "个人所得税") {
            $("#declarationTaxBasis").val("纳税人取得的应纳税所得额");
        } else if (proid == "企业所得税") {
            $("#declarationTaxBasis").val("按应纳税所得额（纳税调整后的利润）");
        }
    });


    function changeCondition(proid) {
        var content;
        //遍历省市数据,把省级下点击的那一个选项的值和省市数据中的
        //省级数据对比,如果相等,取出当前的市的数据
        for (var i = 0; i < china.length; i++) {
            if (proid == china[i].p_id) {
                content = china[i].content;
            }
        }
        //获得市级下拉框对象
        var city = $("#declarationTaxCondition");
        //每次点击省级后,市级初始化,避免高级重复追加
        var option = "<option value=''>--请选择--</option>";
        //遍历市级数据,并取出市级数据,追加到市级对象中
        for (var i = 0; i < content.length; i++) {
            option += "<option value='" + content[i].c_id + "'  ";
            if ('${taxDeclaration.declarationTaxCondition}' == content[i].c_id) {
                option += " selected ";
            }
            option += " num='" + content[i].c_num + "'";
            option += ">" + content[i].c_name + "</option>";
        }
        city.html(option);
    }


    function changeCar(proid) {
        var cities;
        //遍历省市数据,把省级下点击的那一个选项的值和省市数据中的
        //省级数据对比,如果相等,取出当前的市的数据
        for (var i = 0; i < china.length; i++) {
            if (proid == china[i].p_id) {
                cities = china[i].cities;
            }
        }
        //获得市级下拉框对象
        var city = $("#declarationTaxModel");
        //每次点击省级后,市级初始化,避免高级重复追加
        var option = "<option value=''>--请选择--</option>";
        //遍历市级数据,并取出市级数据,追加到市级对象中
        for (var i = 0; i < cities.length; i++) {
            option += "<option value='" + cities[i].c_id + "'  ";
            if ('${taxDeclaration.declarationTaxModel}' == cities[i].c_id) {
                option += " selected ";
            }
            option += ">" + cities[i].c_name + "</option>";
        }
        city.html(option);
    }

    zaneDate({
        elem: '#declarationTaxTime',
        format: 'yyyy-MM-dd',
        min: new Date().Format("yyyy-MM-dd"),
        max: '2027-08-20',
        begintime: '<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss"  value="${taxDeclaration.declarationTaxTime}" />'
    });

    function doChange() {
        var num = jQuery("#declarationTaxCondition  option:selected").attr("num");
        $("#declarationTaxRate").val(num);

    }
</script>
</body>
</html>
